<template>
<div>
  <span>{{label}}</span>
</div>
</template>

<script>
import codeTypeService from "@/service/CodeTypeService";

export default {
name: "translate-code",
  data () {
    return{
      label:''
    }
},
  props:{
    code:{
      type: [String, Number, Array],
      required: true
    },
    codeType:{
      type: String,
      required: true,
    },
  },
  mounted() {
    codeTypeService.getCodeTypeList({codeType: this.codeType}).then(codes=>{
      const result = {needFind: true};
      for (let i = 0; i < codes.length; i++) {
        if (result.needFind) {
          this.recursionSearchData(this.code, codes[i], result)
        } else {
          break
        }
      }
    });
  },
  methods: {
    recursionSearchData : function(code,item,result){
      if (result.needFind){
        if (item.id===code){
          result.needFind = false;
          return this.label = item.label;
        }else if (item.children){
          for(let i =0;i<item.children.length;i++){
            if (result.needFind){
              this.recursionSearchData(code,item.children[i],result);
            }else{
              break
            }
          }
        }
      }
    }
  }
}
</script>

<style scoped>

</style>